package com.tz.init;

import com.tz.AppConfig;
import com.tz.dao.CategoryDao;
import com.tz.dao.ProductDao;
import com.tz.entity.Category;
import com.tz.entity.Product;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by Administrator on 16-7-28.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class InitData {

    @Autowired
    private ProductDao productDao;
    @Autowired
    private CategoryDao categoryDao;

    @Test
    public void init01Categories() {
//        Hibernate: insert into SHOP_CATEGORY (create_date, modify_date, version, c_level, name, category_id, c_remark, c_seq, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
        Category category1 = new Category("ELECTRONICS", null, 0, 0);
        Category category2 = new Category("CLOTHES", null, 0, 1);
        Category category3 = new Category("FOOD", null, 0, 2);
        Category category4 = new Category("HEALTH & BEAUTY", null, 0, 3);
        Category category5 = new Category("SPORTS & LEISURE", null, 0, 4);
        Category category6 = new Category("BOOKS & ENTERTAINMENTS", null, 0, 5);
        categoryDao.save(category1);
        categoryDao.save(category2);
        categoryDao.save(category3);
        categoryDao.save(category4);
        categoryDao.save(category5);
        categoryDao.save(category6);

        categoryDao.save(new Category("Cameras", category1, 1, 0));
        categoryDao.save(new Category("Computers,Tablets&Laptop", category1, 1, 1));

        categoryDao.save(new Category("Men's Clothings", category2, 1, 0));
        categoryDao.save(new Category("Women's Clothings", category2, 1, 1));
        categoryDao.save(new Category("Kids Clothings", category2, 1, 2));

        categoryDao.save(new Category("Angoves", category3, 1, 0));
        categoryDao.save(new Category("French Rabbit", category3, 1, 1));

        categoryDao.save(new Category("Facial Mask", category4, 1, 0));
        categoryDao.save(new Category("Healthy product", category4, 1, 1));

        categoryDao.save(new Category("Addidass", category5, 1, 0));
        categoryDao.save(new Category("Neik", category5, 1, 1));

        categoryDao.save(new Category("Poems", category6, 1, 0));
        categoryDao.save(new Category("Novel", category6, 1, 1));
    }

    @Test
    public void init02Products() {
        productDao.save(new Product("男鞋",12));
        productDao.save(new Product("女鞋",23));
        productDao.save(new Product("手机",1313));
        productDao.save(new Product("相机",32));
        productDao.save(new Product("笔记本",3213));
        productDao.save(new Product("台式机",31));
        productDao.save(new Product("男裤子",321));
        productDao.save(new Product("女裤子",4324));
        productDao.save(new Product("零食",455));
        productDao.save(new Product("日常用品",34));
        productDao.save(new Product("小吃",64));
        productDao.save(new Product("文具",224));
//        Hibernate: insert into SHOP_PRODUCT (create_date, modify_date, version, category_id, p_color, p_desc, p_detail, p_discount, p_is_featured, p_is_latest, p_name, p_price, p_is_sidebar, p_stock, p_subName, p_tax, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    }

}
